﻿<div class="container-fluid">
    <div class="row-fluid">
        <div class="span12">
            <div class="widget-box">
                <form action="@Url.Action("UserList", "User")" method="post">
                <div class="widget-title">
                    <span class="icon"><i class="icon-th"></i></span>
                    <h5>
                        用户信息列表</h5>
                </div>
                <div class="widget-content">
                    <a href="@Url.Action("Info", "User")" class="btn btn-success">添 加 </a>
                    <input type="button" value="批量删除" class="btn btn-danger" onclick="Deletes()" />
                </div>
                <div class="widget-content">
                    <table class="table table-bordered table-striped with-check">
                        <thead>
                            <tr>
                                <th>
                                    <input type="checkbox" id="title-table-checkbox" name="title-table-checkbox" />
                                </th>
                                <th>
                                    ID
                                </th>
                                <th>
                                    用户名
                                </th>
                                <th>
                                    类型
                                </th>
                                <th>
                                    创建时间
                                </th>
                                <th>
                                    操作
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            @{
                                UserBLL bll = new UserBLL();
                                Dictionary<string, string> Rols = bll.GetRoles();
                            }
                            @foreach (HXDNB.DAL.UserInfo item in ViewBag.PagList.DataList)
                            {
                                <tr>
                                    <td>
                                        <input type="checkbox" name="UserID" value="@item.Id" />
                                    </td>
                                    <td>
                                        @item.Id
                                    </td>
                                    <td>
                                        @item.Name
                                    </td>
                                    <td>
                                        @Html.Raw(string.IsNullOrWhiteSpace(item.Role) ? "找不到角色" : Rols[item.Role.Trim()])
                                    </td>
                                    <td>
                                        @item.CreateTime
                                    </td>
                                    <td style="text-align: center">
                                        <a href="@Url.Action("Info", "User", new { id = item.Id })" class="btn btn-primary btn-mini">
                                            更改角色</a>
                                        <input type="button" value="重置密码" class="btn btn-primary btn-mini" onclick="Reset(@item.Id)"  />
                                        <input type="button" value=" 删 除 " class="btn btn-danger btn-mini" onclick="Delete(@item.Id)" />
                                    </td>
                                </tr>
                            }
                        </tbody>
                    </table>
                    @Html.Partial("_Paging")
                </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    //重置用户密码
    function Reset(id) {
        if (confirm("确认重置密码？")) {
            $("#LoadingBox").show();
            $.post('@Url.Action("Reset", "User")', "id=" + id, function (d) {
                $("#LoadingBox").hide();
                alert(d == "True" ? "密码重置成功!" : "密码重置失败!");
            })
        }
    }
    //删除单个栏目
    function Delete(id) {
        if (confirm("确认删除？")) {
            $("#LoadingBox").show();
            $.post('@Url.Action("Delete", "User")', "id=" + id, function (d) {
                $("#LoadingBox").hide();
                //刷新页面，页码不变
                $("form").submit();
            })
        }
    }
    //批量删除栏目
    function Deletes() {
        var obj = $("input:checkbox[name='UserID']:checked");
        if (obj.length == 0) { alert("请至少选择一条数据！"); return; }
        var ids = ""; obj.each(function () { ids += $(this).val() + ","; });
        if (confirm("确认删除" + obj.length + "条数据？")) {
            $("#LoadingBox").show();
            $.post('@Url.Action("Delete", "User")', "id=" + ids, function (d) {
                $("#LoadingBox").hide();
                //刷新页面，页码变为第一页
                $('#PageIndex').val(1);
                $("form").submit();
            })
        }
    }
</script>
